package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarMaintenance;
import com.ruoyi.car.service.ICarMaintenanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修保养Controller
 * 
 * @author ruoyi
 * @date 2022-12-03
 */
@RestController
@RequestMapping("/car/maintenance")
public class CarMaintenanceController extends BaseController
{
    @Autowired
    private ICarMaintenanceService carMaintenanceService;

    /**
     * 查询维修保养列表
     */
    @PreAuthorize("@ss.hasPermi('car:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarMaintenance carMaintenance)
    {
        startPage();
        List<CarMaintenance> list = carMaintenanceService.selectCarMaintenanceList(carMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出维修保养列表
     */
    @PreAuthorize("@ss.hasPermi('car:maintenance:export')")
    @Log(title = "维修保养", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarMaintenance carMaintenance)
    {
        List<CarMaintenance> list = carMaintenanceService.selectCarMaintenanceList(carMaintenance);
        ExcelUtil<CarMaintenance> util = new ExcelUtil<CarMaintenance>(CarMaintenance.class);
        util.exportExcel(response, list, "维修保养数据");
    }

    /**
     * 获取维修保养详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:maintenance:query')")
    @GetMapping(value = "/{maintenanceId}")
    public AjaxResult getInfo(@PathVariable("maintenanceId") Long maintenanceId)
    {
        return success(carMaintenanceService.selectCarMaintenanceByMaintenanceId(maintenanceId));
    }

    /**
     * 新增维修保养
     */
    @PreAuthorize("@ss.hasPermi('car:maintenance:add')")
    @Log(title = "维修保养", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarMaintenance carMaintenance)
    {
        return toAjax(carMaintenanceService.insertCarMaintenance(carMaintenance));
    }

    /**
     * 修改维修保养
     */
    @PreAuthorize("@ss.hasPermi('car:maintenance:edit')")
    @Log(title = "维修保养", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarMaintenance carMaintenance)
    {
        return toAjax(carMaintenanceService.updateCarMaintenance(carMaintenance));
    }

    /**
     * 删除维修保养
     */
    @PreAuthorize("@ss.hasPermi('car:maintenance:remove')")
    @Log(title = "维修保养", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintenanceIds}")
    public AjaxResult remove(@PathVariable Long[] maintenanceIds)
    {
        return toAjax(carMaintenanceService.deleteCarMaintenanceByMaintenanceIds(maintenanceIds));
    }
}
